{% include "header.html"%}
<div class="container">
  <table class="table table-bordered table-striped">
    <tr>
      <th>ID</th>
      <th>名字</th>
      <th>描述</th>
      <th>推送/重推并发数</th>
      <th>推送队列</th>
      <th>订阅状态</th>
      <th>推送状态</th>
      <th>订阅</th>
      <th>操作</th>
      <th>用户</th>
      <th>分组</th>
    </tr>
    {% for task in tasks%}
    <tr>
      <td>{{task.ID}}</td>
      <td>{{task.Name}}</td>
      <td>{{task.Desc}}</td>
      <td>{{task.RoutineCount}}/{{task.ReRoutineCount}}</td>
      <td><a href="/task/detail/{{task.ID}}">详情</a></td>
      <td>
        {%if (task.Stat=="正常")%}
        <span class="label label-success">{{task.Stat}}</span> 
        {%else%}
        <span class="label label-danger">{{task.Stat}}</span> 
        {%endif%}
      </td>
      <td>
          {%if task.PushState == 1%}
          <span class="label label-success">正常</span> 
          {% endif %}
          {%if task.PushState == 0 %}
          <span class="label label-danger">停止</span> 
          {%endif%}
      </td>
      <td>
        <a class="btn btn-info btn-sm" data-toggle="modal" onclick="getDialogTask(this, {{task.ID}})">详情</a>
      </td>
      <td>
        <div class="btn-group">
          <button type="button" class="btn btn-primary btn-sm dropdown-toggle" data-toggle="dropdown">
            操作 <span class="caret"></span>
          </button>
          <ul class="dropdown-menu">
            <li><a href="/task/log/{{task.ID}}">错误日志</a></li>
            <li role="separator" class="divider"></li>
            <li><a href="/taskmodify/{{task.ID}}" class="modify-task">修改</a></li>
            <li><a href="javascript:void(0)" onclick="deleteTask({{task.ID}})" class="delete-task">删除</a></li>
            <li><a href="javascript:void(0)" onclick="copyTaskDialog({{task.ID}}, '{{task.Name}}')" class="copy-task">复制</a></li>
            <li role="separator" class="divider"></li>
            {% if (task.Stat == "正常")%}
            <li><a href="javascript:void(0)" onclick="changeTaskStat({{task.ID}},'停止')">停止订阅</a></li>
            {% else %}
            <li><a href="javascript:void(0)" onclick="changeTaskStat({{task.ID}},'正常')">启动订阅</a></li>
            {% endif %}
            {% if task.PushState == 1%}
            <li><a href="javascript:void(0)" onclick="changePushState({{task.ID}}, 0)">停止推送</a></li>
            {% else %}
            <li><a href="javascript:void(0)" onclick="changePushState({{task.ID}}, 1)">启动推送</a></li>
            {% endif %}
            {% if user.Role >= 3 %}
            <li role="separator" class="divider"></li>
            <li><a href="/task/updateuser/{{task.ID}}">更改任务用户</a></li>
            {% endif %}
          </ul>
        </div>
      </td>
      <td>{{task.CreateUser}}</td>
      <td>{{task.Category}}</td>
    </tr>
    {% endfor%}
  </table>
  <div class="modal fade" id="copyTaskModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title" id="myModalLabel">复制任务到其他数据库实例</h4>
        <p>(注意：复制后的任务状态默认是停止，需要手动开启)</p>        
      </div>
      <div class="modal-body">
        <form id="copyTaskForm">
          <input type="hidden" name="taskid" value="">
          <div class="form-group">
						<div class="form-inline">
							<label for="name">任务名称</label>
							<p class="form-control-static">(只能是数字、字母、下划线；长度不超过50；不能修改)</p>
						</div>
						<input class="form-control" type="text" name="taskName" id="taskName" value="">
					</div>
          <div class="form-group">
						<div class="form-inline">
							<label for="name">数据库实例</label>
						</div>
						<select class="form-control" name="dbInstanceName">
            {%for client in clients%}
              <option value="{{client.Desc}}">{{client.Desc}}</option>
            {%endfor%}
            </select>
					</div>
        </form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
        <button type="button" class="btn btn-primary" onclick="copyTask()">复制</button>
      </div>
    </div>
  </div>
</div>
</div>
{% include "footer.html"%}
